package cn.ava.basic.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
/**
 * @ClassName: SendmailUtil
 * @Description: 发送邮件工具类
 * @Author: Avavaava
 * @Date: 2022/7/11 16:24
 * @version: 23.53
 *
 */
public class SendmailUtil {

    private static JavaMailSender javaMailSender = SpringUtil.getBean(JavaMailSender.class);

    public static void sendMail(String sendEmail,String acceptEmail,String subject,String text,Boolean isHtml) {
        try {
            // 发送激活邮件给用户
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            // 复杂邮箱,支持html
            MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage,true,"utf-8");
            // 设置发送人邮箱
            mailMessage.setFrom(sendEmail);
            // 设置接收人邮箱
            mailMessage.setTo(acceptEmail);
            // 设置邮件主题
            mailMessage.setSubject(subject);
            // 邮箱内容
            mailMessage.setText(text,isHtml);
            // 发送邮箱
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }

}